/**
 * 
 */
package com.shanglida.main.find;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.shanglida.R;

/**
 * @author liu
 * @deprecated 加载尚礼达WEB网站的页面
 * @date 2014-02-28
 * @version 1.0
 * @copyright 广州尚礼达信息科技有限公司
 */
public class WebActivity extends Activity {
	// mWebView webview 界面
	private WebView mWebView;
	private Button mret;

	String URL;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.web_activity);

		Bundle extras = getIntent().getExtras();
		URL = (String) extras.get("URL");

		mret = (Button) findViewById(R.id.web_return);
		mWebView = (WebView) this.findViewById(R.id.sangweb);
		// 加载自定义web网址
		mWebView.loadUrl(URL);

		WebSettings webSettings = mWebView.getSettings();
		// 设置WebView属性，能够执行Javascript脚本
		webSettings.setJavaScriptEnabled(true);
		// 设置禁止访问文件数据
		webSettings.setAllowFileAccess(false);
		// 设置是支持缩放
		webSettings.setBuiltInZoomControls(true);

		MyWebViewClient myWebViewClient = new MyWebViewClient();
		mWebView.setWebViewClient(myWebViewClient);
		mret.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	private class MyWebViewClient extends WebViewClient {
		// 重写父类方法，让新打开的网页在当前的WebView中显示
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
	}

	// 设置回退
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
			mWebView.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
